package bavaria.hightec.banking;

import java.util.Date;
import java.util.Iterator;


public class AccountingList<E> {
	
	Money start = new Money(0,Currency.EUR);
	Date date = new Date();
	public Element <E> first = new Element<E>(date,start,"start"); // date, amount, matter
	public Element <E> position;
	
	
	public AccountingList(){
		first.next=null;
		position=first;
	}
	
	
	public void add(Object accounting,Object amount,Object matter){
		Element<E> neu = new Element<E>(accounting,amount,matter);
		if(position==first){
			first.next=neu;
			neu.next=null;
			position=neu;
		}
		else if(position!=first){
			position.next=neu;
			position=neu;
		}
    }
	
	public void clear(){
		position=first;
		while(position!=null){
			position.next=position;
			position=null;
		}
		first.next=null;
	}
	
	public Object next(){
		if(position.next!=null){
		position=position.next;
		return position.getData();
		}
		else
			return position.next;	
	}
	
	public void resetIteration(){
		position=first;
	}
		
	

	public void print(){
		position=position.next;
		System.out.println(position.getData());
	}
	
	public Iterator<E> iter(){
		return new Iter();
	}
	
	private class Iter implements Iterator{

		@Override
		public boolean hasNext() {
			if(position.next != null)
				return true;
			else
				return false;
		}

		@Override
		public Object next() {
			return AccountingList.this.next();
		}

		@Override
		public void remove() {
		position = first;
		}
	
	}

	
}

